package labb3;

import java.io.Serializable;

/**
 * Abstract class used by the extending class to create a specialized Media
 * object.
 *
 * @author Mikko Puustinen
 * @version 0.4, 2007-okt-14
 */
public abstract class Media implements Serializable, Comparable {
    private String title;
    private String productionDate;
    private String releaseDate;
    private String purchaseDate;
    private String rating;
    private static final long serialVersionUID = -1084182406387697670L;

    /**
     * Return the title.
     *
     * @return the title.
     */
    public String getTitle() {
        return title;
    }

    /**
     * Set the title of the object.
     *
     * @param title the title.
     */
    void setTitle(String title) {
        this.title = title;
    }

    /**
     * Get the production date of the object.
     *
     * @return the production date.
     */
    public String getProductionDate() {
        return productionDate;
    }

    /**
     * Set the production date.
     *
     * @param productionDate the production date.
     */
    public void setProductionDate(String productionDate) {
        this.productionDate = productionDate;
    }

    /**
     * Return the release date of the Media.
     *
     * @return the release date.
     */
    public String getReleaseDate() {
        return releaseDate;
    }

    /**
     * Set the release date.
     *
     * @param releaseDate the release date.
     */
    public void setReleaseDate(String releaseDate) {
        this.releaseDate = releaseDate;
    }

    /**
     * Get the purchase date.
     *
     * @return the purchase date.
     */
    public String getPurchasedDate() {
        return purchaseDate;
    }

    /**
     * Set the purchase date.
     *
     * @param purchaseDate the purchase date.
     */
    public void setPurchaseDate(String purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    /**
     * Get the user rating of the object.
     *
     * @return the rating.
     */
    public String getRating() {
        return rating;
    }

    /**
     * Set the rating.
     *
     * @param rating the rating.
     */
    public void setRating(String rating) {
        this.rating = rating;
    }

    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     * <p/>
     * <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
     * -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
     * implies that <tt>x.compareTo(y)</tt> must throw an exception iff
     * <tt>y.compareTo(x)</tt> throws an exception.)
     * <p/>
     * <p>The implementor must also ensure that the relation is transitive:
     * <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
     * <tt>x.compareTo(z)&gt;0</tt>.
     * <p/>
     * <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
     * implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for all
     * <tt>z</tt>.
     * <p/>
     * <p>It is strongly recommended, but <i>not</i> strictly required that
     * <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any
     * class that implements the <tt>Comparable</tt> interface and violates this
     * condition should clearly indicate this fact.  The recommended language is
     * "Note: this class has a natural ordering that is inconsistent with
     * equals."
     * <p/>
     * <p>In the foregoing description, the notation <tt>sgn(</tt><i>expression</i><tt>)</tt>
     * designates the mathematical <i>signum</i> function, which is defined to
     * return one of <tt>-1</tt>, <tt>0</tt>, or <tt>1</tt> according to whether
     * the value of <i>expression</i> is negative, zero or positive.
     *
     * @param o the object to be compared.
     *
     * @return a negative integer, zero, or a positive integer as this object is
     *         less than, equal to, or greater than the specified object.
     *
     * @throws ClassCastException if the specified object's type prevents it
     *                            from being compared to this object.
     */
    public int compareTo(Object o) {
        return this.title.compareTo(((Media)o).getTitle());
    }

    /**
     * Returns a string representation of the object.
     *
     * @return a string representation of the object.
     */
    public String toString() {
        return title;
    }
}
